package com.atguigu.product.mq.listener;

import cn.hutool.core.date.DateUtil;
import com.atguigu.order.bean.Order;
import com.atguigu.product.bean.Product;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import java.util.stream.Collectors;

@Slf4j
@Component
@RocketMQMessageListener(topic = "${good-success-topic}", consumerGroup = "${good-success-group}")
public class GoodSuccessListener implements RocketMQListener<Order> {
    @Override
    public void onMessage(Order order) {
        StringBuilder sb = new StringBuilder();
        sb.append(order.getNickName() + " 购买");
        sb.append(order.getProductList().stream().map(Product::getProductName).collect(Collectors.joining("、")));
        sb.append("成功，时间：" + DateUtil.now());
        log.info(sb.toString());
    }
}
